package com.jspxcms.plug.web.fore;

import com.jspxcms.common.util.JsonResponse;
import com.jspxcms.core.domain.Site;
import com.jspxcms.core.domain.User;
import com.jspxcms.core.domain.UserDetail;
import com.jspxcms.core.support.Context;
import com.jspxcms.core.support.ForeContext;
import com.jspxcms.plug.domain.PlugHospital;
import com.jspxcms.plug.domain.UserExchange;
import com.jspxcms.plug.service.UserExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yuanyue on 14-10-2.
 */
@Controller
public class GoodsApplyController {
    @RequestMapping(value = "/my_goods_apply.jspx")
    public Object postApply(Integer goodsId,
                            String goodsTitle,
                            Integer goodsScore,
                            String postuser,
                            String telephone,
                            String address,
                            HttpServletRequest request,
                            HttpServletResponse response) {
        response.setHeader("Content-type", "text/html");
        User user = Context.getCurrentUser(request);
        if (user == null) {
            return JsonResponse.jsonOutput(response, -1, "请先登录");
        }

        UserExchange userExchange = new UserExchange();
        userExchange.setUserId(user.getId());
        userExchange.setCreationDate(new Date());
        userExchange.setAddress(address);
        userExchange.setPhone(telephone);
        userExchange.setPostuser(postuser);
        userExchange.setGoodsId(goodsId);
        userExchange.setGoodsTitle(goodsTitle);
        userExchange.setGoodsScore(goodsScore);

        exchangeService.save(userExchange);

        if (userExchange.getId() > 0) {

        }
        return JsonResponse.jsonOutput(response, 1, "申请成功");
    }

    @Autowired
    private UserExchangeService exchangeService;

}
